 /**
 *******************************************************************************
 * @FileName  : main.c
 * @Author    : GaoQiu
 * @CreateDate: 2020-05-18
 * @Copyright : Copyright(C) GaoQiu
 *              All Rights Reserved.
 *******************************************************************************
 */
#include "platform/platform.h"
#include "app_config.h"
#include "gpio.h"
#include "exit.h"
#include "uart.h"
#include "flash.h"
#include "timer.h"
#include "watchdog.h"
#include "aes.h"
#include "pwm.h"
#include "pm.h"
#include "iic.h"
#include "spi.h"
#include "adc.h"

#include "utils/track.h"

/*! Peripheral demo define. */
#define PERIPH_ID_GPIO   0
#define PERIPH_ID_EXIT   1
#define PERIPH_ID_UART   2
#define PERIPH_ID_FLASH  3
#define PERIPH_ID_TIMER  4
#define PERIPH_ID_WDG    5
#define PERIPH_ID_AES    6
#define PERIPH_ID_PWM    7
#define PERIPH_ID_PM     8
#define PERIPH_ID_IIC    9
#define PERIPH_ID_SPI    10
#define PERIPH_ID_ADC    11

#define PERIPH_ID        PERIPH_ID_GPIO



typedef void (*Setup_t)(void);
typedef void (*Loop_t)(void);

static const Setup_t setup[] = {
	GPIO_SetUp,
	EXIT_SetUp,
	UART_SetUp,
	FLASH_SetUp,
	TIMER_SetUp,
	WDG_SetUp,
	AES_SetUp,
	PWM_SetUp,
	PM_SetUp,
	IIC_SetUp,
	SPI_SetUp,
	ADC_SetUp,
};

static const Loop_t loop[] ={
	GPIO_Loop,
	EXIT_Loop,
	UART_Loop,
	FLASH_Loop,
	TIMER_Loop,
	WDG_Loop,
	AES_Loop,
	PWM_Loop,
	PM_Loop,
	IIC_Loop,
	SPI_Loop,
	ADC_Loop,
};

RAM_CODE void irq_handler(void)
{
	UART_IRQHandler();

	TIMER_IRQHandler();

	EXIT_IRQHandler();
}

int main(void)
{
	SystemInit();

	/* FHS clock 48M */
	RCC_SetFhs(FHS_SRC_48M);
	RCC_SetSysClk(SYS_CLK_SRC_FHS, 3);//set system clock to 48M

	TrackSystemInit();

	setup[PERIPH_ID]();

	IRQ_Enable();

	for(;;)
	{
		loop[PERIPH_ID]();

		TRACK_START();
	}
}
